<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>layui</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<link rel="stylesheet" href="__static/lib/layui-v2.5.5/css/layui.css" media="all">
	<link rel="stylesheet" href="__static/css/public.css" media="all">
	<style>
		.layui-form-pane .layui-form-label {
			width: 90px;
		}
		
	</style>
	
</head>
<body>
<div class="layuimini-container">
	<div class="layuimini-main">
        <fieldset class="table-search-fieldset layuimini-container">
            <legend>搜索信息</legend>
            <form class="layui-form layui-form-pane" action="">
                <div class="layui-form-item" style="margin-bottom: 5px;">
                    <div class="layui-inline">
                        <label class="layui-form-label">标题</label>
                        <div class="layui-input-inline">
                            <input type="text" name="title" autocomplete="off" placeholder="请输入标题" class="layui-input">
                        </div>
                        <label class="layui-form-label">标签</label>
                        <div class="layui-input-inline">
                            <select name="label_id"  lay-search="" autocomplete="off" >
                                <option value="">直接选择或搜索选择</option>
                                {volist name="label" id='l'}
									<option value="{$l.id}" >{$l.name}</option>
								{/volist}
                            </select>
                        </div>
                        <label class="layui-form-label">作者</label>
                        <div class="layui-input-inline">
                            <select name="author_id"  lay-search="" autocomplete="off" >
                                <option value="">直接选择或搜索选择</option>
								{volist name="author" id='zz'}
									<option value="{$zz.id}" >{$zz.name}</option>
								{/volist}
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <button type="button" class="layui-btn layui-btn-primary" lay-submit lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
                    </div>
                </div>
            </form>
        </fieldset>
		<script type="text/html" id="channel_toolbar">
			<div class="layui-btn-container">
				<button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="add"> 添加文案 </button>
				<button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="add_author"> 添加作者 </button>
				<button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="add_label"> 添加标签 </button>
				<!-- <button class="layui-btn layui-btn-sm layui-btn-danger data-delete-btn" lay-event="delete"> 删除 </button> -->
			</div>
		</script>

		<table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

		<script type="text/html" id="currentTableBar">
            <a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="info">详情</a>
			<a class="layui-btn layui-btn-danger layui-btn-xs " lay-event="edit">修改</a>
		</script>
		<script type="text/html" id="fansTable">
			<span style="{{d.platform==1?'':'display:none'}}" >快手</span>
			<span style="{{d.platform==2?'':'display:none'}}" >知乎</span>
			<span style="{{d.platform==3?'':'display:none'}}" >抖音</span>
			<span style="{{d.platform==4?'':'display:none'}}" >微信</span>
		</script>
		
	</div>
</div>
<script src="__static/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script src="__static/js/lay-config.js?v=1.0.4" charset="utf-8"></script>
<script>
//添加
function get_add(){ 
	layer.open({
        type: 2,
        title:'添加文案信息',
        area: ['80%', '90%'],
        fixed: false, //不固定
        maxmin: true,
        shadeClose:false,	//点击遮罩后关闭提示框
        scrollbar:false, //- 是否允许浏览器出现滚动
        content: "{:url('add_copywriter')}" 
    });
    //layer.full(index);
}
// 详情
function get_info_copywriter(id){
	layer.open({
        type: 2,
        title:'文案详情',
        area: ['90%', '90%'],
        fixed: false, //不固定
        maxmin: true,
        shadeClose:false,	//点击遮罩后关闭提示框
        scrollbar:false, //- 是否允许浏览器出现滚动
        content: "{:url('info_copywriter')}?id="+id 
    });
    //layer.full(index);
}
//修改
function get_save(id){
	layer.open({
        type: 2,
        title:'修改文案信息',
        area: ['80%', '90%'],
        fixed: false, //不固定
        maxmin: true,
        shadeClose:false,	//点击遮罩后关闭提示框
        scrollbar:false, //- 是否允许浏览器出现滚动
        content: "{:url('save_copywriter')}?id="+id 
    });
    //layer.full(index);
}
// 添加作者和标签
function add_author_label(type){
	layer.prompt({title: '请输入作者或标签',},function(value, index){
		layer.load(1, { shade : [ 0.5, '#676a6c' ] }); 
		$.post("{:url('add_author_label')}?t=json",{name:value,type:type},function(data){
			layer.closeAll();
			if (data['code'] == 1) { 
				layer.msg(data['msg'], { icon : 6 });
			} else {
				layer.msg(data['msg'], { icon : 5 });
			}
		});
		layer.close(index);
	});
}
	var $,form,table;
	layui.use(['form', 'table'], function () {
		$ = layui.jquery
			, form = layui.form
			, table = layui.table;

		table.render({
			elem: '#currentTableId',
			height: 'full-150',
			id:'testReload',
			url: '{:url("copywriter")}?t=json',
			method : 'post',
			toolbar: '#channel_toolbar',
			cols: [[
				{ field: 'title', title: '标题' },
				{ field: 'describe', title: '描述',},
				{ field: 'labels', title: '标签'},
				{ field: 'platform', title: '平台',toolbar: '#fansTable',},
				{ field: 'author', title: '作者'},
				{ field: 'create_time', title: '创建时间' },
				{ title: '操作', width: 150, fixed: 'right', toolbar: '#currentTableBar', align: "center" }
			]],
			limit: 30,
			page: true,
			skin: 'line',
		});

		/**
		 * toolbar监听事件
		 */
		table.on('toolbar(currentTableFilter)', function (obj) {
			switch (obj.event) {
				case 'add':
					get_add();
				break;
				case 'add_author':
					add_author_label(1);
				break;
				case 'add_label':
					add_author_label(2);
				break;
			}
		});
		//监听操作栏事件
		table.on('tool(currentTableFilter)', function (obj) {
			var data = obj.data;
			switch (obj.event) {
				case 'edit':
					get_save(data.id);
				break;
				case 'info':
					get_info_copywriter(data.id);
				break;
			}
		});
		//搜索
		form.on('submit(data-search-btn)', function(data){
			var articleFrom = data.field;
			table.reload('testReload', {
			  	url: '{:url("copywriter", ["t"=>"json"])}',
				where:articleFrom
			});
			return false;
		});

	});
	
	
	//重载数据表
	function get_s(msg){
		table.reload('testReload', {
			  url: '{:url("copywriter")}?t=json',
			});
		layer.msg(msg, {icon: 6});
	}
</script>

</body>
</html>